﻿using System;
using Headsight.BPMN2WF.BPMN.Model;
using Headsight.BPMN2WF.BPMN.Utils;

namespace Headsight.BPMN2WF.Transformation.Transformers.Additions
{
    public class BPMN2WFTransformationExceptionHandler : BPMN2WFTransformationDelegateBaseImpl
    {
        public BPMN2WFTransformationExceptionHandler(IBPMN2WFTransformation @delegate) : base(@delegate)
        {
        }

        public override BPMNTransformationResult Transform(IBPMN2WFTransformationContext ctx, BPMNFlowNode flowNode)
        {
            try
            {
                return Delegate.Transform(ctx, flowNode);
            }
            catch (Exception e)
            {
                 throw new Exception(String.Format("{0} / {1} / {2}",
                     flowNode, flowNode.BPMNFlowNodeOrNodeIn(), 
                     flowNode.BPMNFlowNodeOrNodeIn().TElement.name), e);
            }
        }
    }
}